import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 全部引入element-plus样式文件
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 全部引入Icon模块
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// 引入全局的一些样式文件
import '@/assets/styles/global.less'
// 中英文切换功能
import i18n from './i18n/index'
// 导入echarts
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app
    .use(store)
    .use(ElementPlus, { size: 'samll', zIndex: 3000 })
    .use(router)
    .use(i18n)
    .mount('#app')

// 解决页面重置报错的问题，在vue3中使用element-plus页面重置时报错
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}